package cn.test;

import com.sun.org.glassfish.gmbal.Description;
import javafx.scene.control.Cell;

import javax.swing.*;
import java.awt.*;

/*
*
 * @ClassName View
 * @Description TODO
 * @Author 郑万富
 * @Date 2020/11/9 10:37
 * @Version 1.0
public class View extends JPanel {
    private static final long serialVersionUID = -5258995676212660595L;
    private static final int GRID_SIZE = 20; // 定义可视化网格常量尺寸
    private Field theField;  // 定义细胞容器对象

    public View(Field field) {  // 定义视图构造器
        theField = field;
    }
    //paint方法调用cell中的draw绘制图像，没有这个方法，界面就无法显示
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        for (int row = 0; row < theField.getHeight(); row++) {
            for (int col = 0; col < theField.getWidth(); col++) {
                Cell cell = theField.getCell(row, col);
                if (cell != null) {
                    cell.draw(g, col * GRID_SIZE, row * GRID_SIZE, GRID_SIZE);
                }
            }
        }
    }
    @Override
    public Dimension getPreferredSize() {
        //Dimension类封装单个对象中组件的宽度和高度（以整数精度）。
        //这里设置的是panel的大小
        return new Dimension(theField.getWidth() * GRID_SIZE + 1,
                theField.getHeight() * GRID_SIZE + 1);
    }

}
*/


